﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using mfXmlSerializer.TestObjects;
using System.IO;
using System.Threading;
using System.Globalization;
using System.Diagnostics;

namespace mfXmlSerializer.Test
{
    [TestClass]
    public class MapTests
    {
        [TestMethod]
        public void Map_ParameterObject()
        {
            var para = TestDataFactory.CreateSimpleCompleteParameter();

            var map = mfSerializationMapCreator.CreateMapForType(para.GetType());

            Assert.AreEqual(5, map.SerializationElements.Count);

            Assert.AreEqual("Version", map.SerializationElements[0].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].GetType());

            Assert.AreEqual("Number", map.SerializationElements[1].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[1].GetType());

            Assert.AreEqual("FloatNumber", map.SerializationElements[2].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[2].GetType());

            Assert.AreEqual("Created", map.SerializationElements[3].Name);
            Assert.AreEqual(typeof(mfMapDateTimeElement), map.SerializationElements[3].GetType());

            Assert.AreEqual("LogConfig", map.SerializationElements[4].Name);
            Assert.AreEqual(typeof(mfMapClassElement), map.SerializationElements[4].GetType());
            Assert.AreEqual(true, map.SerializationElements[4].HasChildMap);

            Assert.AreEqual(2, map.SerializationElements[4].ChildMap.SerializationElements.Count);

            Assert.AreEqual("TraceLevel", map.SerializationElements[4].ChildMap.SerializationElements[0].Name);
            Assert.AreEqual(typeof(mfMapEnumElement), map.SerializationElements[4].ChildMap.SerializationElements[0].GetType());

            Assert.AreEqual("FileLoggingActive", map.SerializationElements[4].ChildMap.SerializationElements[1].Name);
            Assert.AreEqual(typeof(mfMapBooleanElement), map.SerializationElements[4].ChildMap.SerializationElements[1].GetType());
        }

        [TestMethod]
        public void Map_RSSSampleObject()
        {
            var rss = TestDataFactory.CreateRSSSample_Complete();

            var map = mfSerializationMapCreator.CreateMapForType(rss.GetType());

            Assert.AreEqual(1, map.SerializationElements.Count);

            //ChannelCollection
            Assert.AreEqual("channel", map.SerializationElements[0].Name);
            Assert.AreEqual(typeof(mfMapArrayListElement), map.SerializationElements[0].GetType());

            Assert.AreEqual(true, map.SerializationElements[0].HasChildMap);
            Assert.AreEqual(11, map.SerializationElements[0].ChildMap.SerializationElements.Count);

            Assert.AreEqual("title", map.SerializationElements[0].ChildMap.SerializationElements[0].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[0].GetType());

            Assert.AreEqual("link", map.SerializationElements[0].ChildMap.SerializationElements[1].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[1].GetType());

            Assert.AreEqual("description", map.SerializationElements[0].ChildMap.SerializationElements[2].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[2].GetType());

            Assert.AreEqual("language", map.SerializationElements[0].ChildMap.SerializationElements[3].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[3].GetType());

            Assert.AreEqual("pubDate", map.SerializationElements[0].ChildMap.SerializationElements[4].Name);
            Assert.AreEqual(typeof(mfMapDateTimeElement), map.SerializationElements[0].ChildMap.SerializationElements[4].GetType());

            Assert.AreEqual("lastBuildDate", map.SerializationElements[0].ChildMap.SerializationElements[5].Name);
            Assert.AreEqual(typeof(mfMapDateTimeElement), map.SerializationElements[0].ChildMap.SerializationElements[5].GetType());

            Assert.AreEqual("docs", map.SerializationElements[0].ChildMap.SerializationElements[6].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[6].GetType());

            Assert.AreEqual("generator", map.SerializationElements[0].ChildMap.SerializationElements[7].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[7].GetType());

            Assert.AreEqual("managingEditor", map.SerializationElements[0].ChildMap.SerializationElements[8].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[8].GetType());

            Assert.AreEqual("webMaster", map.SerializationElements[0].ChildMap.SerializationElements[9].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[9].GetType());

            //ItemCollection
            Assert.AreEqual("item", map.SerializationElements[0].ChildMap.SerializationElements[10].Name);
            Assert.AreEqual(typeof(mfMapArrayListElement), map.SerializationElements[0].ChildMap.SerializationElements[10].GetType());

            Assert.AreEqual(true, map.SerializationElements[0].ChildMap.SerializationElements[10].HasChildMap);
            Assert.AreEqual(5, map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements.Count);

            Assert.AreEqual("title", map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[0].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[0].GetType());

            Assert.AreEqual("link", map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[1].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[1].GetType());

            Assert.AreEqual("description", map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[2].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[2].GetType());

            Assert.AreEqual("pubDate", map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[3].Name);
            Assert.AreEqual(typeof(mfMapDateTimeElement), map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[3].GetType());

            Assert.AreEqual("guid", map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[4].Name);
            Assert.AreEqual(typeof(mfMapSimpleElement), map.SerializationElements[0].ChildMap.SerializationElements[10].ChildMap.SerializationElements[4].GetType());
        }


    }
}
